/**
 * 
 */
package vanhoc.android.utils;

import com.telpoo.truyencuoi.R;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;

/**
 * @author SEVEN
 *
 */
public class TabBar{

	private Context _context;
	private TabHost _tabhost;
	
	//constructor
	public TabBar(Context ct, TabHost th) {
		_context = ct;
		_tabhost = th;
	}
	
	
	
	public void addTab(TabSpec tabspec){
		_tabhost.addTab(tabspec);
	}
	
	
	/**
	 * create a tab
	 * @param intentClass
	 * @param tag
	 * @param title
	 * @param drawable
	 * @return
	 */
	public TabSpec createTab(final Class<?> intentClass,final String tag,final String title, int drawable){
    	final Intent intent = new Intent().setClass(_context, intentClass);
    	View tab = LayoutInflater.from(_tabhost.getContext()).inflate(R.layout.tab, null);
    	//((TextView)tab.findViewById(R.id.tab_text)).setText(title);
        //((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);
    	
    	TextView tabTitle = (TextView) tab.findViewById(R.id.tab_text);
    	tabTitle.setText(title);
    	
		return _tabhost.newTabSpec(tag).setIndicator(tab).setContent(intent);
    }
	
	
	/**
	 * create a tab
	 * @param intentClass
	 * @param tag
	 * @param title
	 * @param drawable
	 * @return
	 */
	public TabSpec createTab(final Class<?> intentClass,final String tag,final String title){
		final Intent intent = new Intent().setClass(_context, intentClass);
    	intent.putExtra("TAG", tag);
    	View tab = LayoutInflater.from(_tabhost.getContext()).inflate(R.layout.tab, null);
    	TextView tabTitle = (TextView) tab.findViewById(R.id.tab_text);
    	tabTitle.setText(title);
    	
		return _tabhost.newTabSpec(tag).setIndicator(tab).setContent(intent);
    }
	
	/**
	 * create a tab
	 * @param intentClass
	 * @param tag
	 * @param title
	 * @param drawable
	 * @return
	 */
	public TabSpec createTab(final Class<?> intentClass,String intentKey,String intentValue, final String tag,final String title){
    	final Intent intent = new Intent().setClass(_context, intentClass);
    	intent.putExtra(intentKey, intentValue);
    	View tab = LayoutInflater.from(_tabhost.getContext()).inflate(R.layout.tab, null);
    	((TextView)tab.findViewById(R.id.tab_text)).setText(title);
    	
		return _tabhost.newTabSpec(tag).setIndicator(tab).setContent(intent);
    }
	
	/**
	 * create a tab
	 * @param intentClass
	 * @param tag
	 * @param title
	 * @param drawable
	 * @return
	 */
	public TabSpec createTab(final Class<?> intentClass,String intentKey,int intentValue, final String tag,final String title){
    	final Intent intent = new Intent().setClass(_context, intentClass);
    	intent.putExtra(intentKey, intentValue);
    	View tab = LayoutInflater.from(_tabhost.getContext()).inflate(R.layout.tab, null);
    	((TextView)tab.findViewById(R.id.tab_text)).setText(title);
    	
		return _tabhost.newTabSpec(tag).setIndicator(tab).setContent(intent);
    }
	
	/**
	 * create a tab
	 * @param intentClass
	 * @param tag
	 * @param title
	 * @param drawable
	 * @return
	 */
	public TabSpec createTab(final Class<?> intentClass,String intentKey,Boolean intentValue, final String tag,final String title){
    	final Intent intent = new Intent().setClass(_context, intentClass);
    	intent.putExtra(intentKey, intentValue);
    	View tab = LayoutInflater.from(_tabhost.getContext()).inflate(R.layout.tab, null);
    	((TextView)tab.findViewById(R.id.tab_text)).setText(title);
    	
		return _tabhost.newTabSpec(tag).setIndicator(tab).setContent(intent);
    }
	
	
	
	public void setChildrenTabWidth(int index, int width){
		_tabhost.getTabWidget().getChildAt(index).getLayoutParams().width = width;
	}
	
	public void setChildrenTabHeight(int index, int height){
		_tabhost.getTabWidget().getChildAt(index).getLayoutParams().height = height;
	}
	
	public void setCurrentTab(int index){
		_tabhost.setCurrentTab(index);
	}
}
